# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=discount

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.6
pkgrel=1
pkgdesc="A Markdown implementation written in C (mingw-w64)"
arch=('any')
url="http://www.pell.portland.or.us/~orc/Code/discount/"
license=('custom:BSD')
provides=('markdown')
conflicts=('markdown')
options=('strip' 'staticlibs')
source=(http://www.pell.portland.or.us/~orc/Code/discount/${_realname}-$pkgver.tar.bz2
    discount-mingw-building.patch)
md5sums=('6f44e627777b6392f8f4a3280642482a'
         '5235a54f0a3e8e61a11c42f3541e9582')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p0 -i ${srcdir}/discount-mingw-building.patch
}

build() {
    cd "${srcdir}"/${_realname}-${pkgver}
  sed -e "s/m 444/m 644/g" -i configure.inc
  export CFLAGS="-O2 -pipe -I${MINGW_PREFIX}/include"
  MSYSTEM=MINGW \
  CC=${MINGW_PREFIX}/bin/gcc.exe \
  AC_CPP_PROG=${MINGW_PREFIX}/bin/cpp.exe \
  AC_LN_PROG="cp -pR" \
  ./configure.sh \
      --prefix=${MINGW_PREFIX} \
      --enable-all-features \
    --shared
    make
}

package() {
    cd "$srcdir/${_realname}-$pkgver"
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,include,lib}
  make DESTDIR="$pkgdir" install.everything
  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  install -Dm644 COPYRIGHT "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
